Skip to content

Unify GSC analytics response contract and status-driven consumers#429

Closed
AJaySi wants to merge 1 commit intomainfrom
codex/define-consistent-response-contract-for-get_search_analytics-ren1d4
Closed

Unify GSC analytics response contract and status-driven consumers#429
AJaySi wants to merge 1 commit intomainfrom
codex/define-consistent-response-contract-for-get_search_analytics-ren1d4

Conversation

@AJaySi
Copy link
Owner

@AJaySi AJaySi commented Mar 12, 2026

Motivation

  • Ensure get_search_analytics always returns a single, predictable shape so downstream code can rely on keys rather than presence checks.
  • Replace ad-hoc early returns (auth failure, not connected, no data, verification/API errors, exceptions) with structured responses that include a status marker and empty collections.
  • Normalize cached/legacy payloads so previously cached responses conform to the new contract.
  • Simplify and harden consumers (handler, scheduler, onboarding normalizers) to use status + guaranteed keys instead of brittle key-existence logic.

Description

  • Added helper builders inside GSCService.get_search_analytics: _base_payload(status, error) and _normalize_payload(payload) that guarantee the unified contract with keys: overall_metrics.rows, query_data.rows, page_data.rows, query_page_data.rows, verification_data.rows, date_range (start/end), site_url, startDate/endDate/siteUrl aliases, status, and optional error/warning.
  • Refactored all early-return branches in get_search_analytics to return the canonical payload with appropriate status values (examples: not_connected, auth_failed, no_data, verification_failed, api_error, partial_success, success, error) and empty arrays instead of ad-hoc dict shapes.
  • Normalized successful and partial-success responses to include canonical date_range, site_url, and status and ensure cached responses are converted via _normalize_payload before being returned.
  • Updated consumers to rely on status and guaranteed keys: backend/services/analytics/handlers/gsc_handler.py now derives metrics from overall_metrics/query_data and computes connection status from status; backend/services/scheduler/executors/gsc_insights_executor.py checks status rather than presence of 'error'; onboarding normalizer normalize_gsc_analytics gates processing based on status.

Testing

  • Ran python -m compileall backend/services/gsc_service.py backend/services/analytics/handlers/gsc_handler.py backend/services/scheduler/executors/gsc_insights_executor.py backend/api/content_planning/services/content_strategy/autofill/normalizers/analytics_normalizer.py and all modified modules compiled without syntax errors.
  • No automated unit tests were added or modified as part of this change.

Codex Task

@AJaySi AJaySi closed this Mar 22, 2026
AJaySi added a commit that referenced this pull request Mar 22, 2026
huggingface_provider.py:
- Add retry logic with _should_retry_hf_error and _is_non_retryable_hf_error
- Update default models from :groq to :cerebras (HF_FALLBACK_MODELS)
- Add fallback_models parameter to huggingface_text_response
- Add get_available_models with updated model list

main_text_generation.py:
- Add GPT_PROVIDER and TEXTGEN_AI_MODELS env var support
- Add preferred_provider and flow_type parameters to llm_text_gen
- Add HF_MODEL_MAPPING for short model name resolution
- Add flow_type logging tag for better observability

sif_agents.py:
- Add LOW_COST_SHARED_REMOTE_MODELS for SIF agents
- Update SharedLLMWrapper to use preferred_hf_models and flow_type

These changes preserve the modular textgen_utils structure while incorporating
the useful routing and retry logic improvements from the pending PRs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant